#!/usr/bin/env python

import meilanweb as web

@web.wsgize
def index(req):
    return '<html><body>Hello, world!</body></html>'

@web.wsgize
def exception(req):
    raise Exception('asdf')

@web.wsgize
def redirect(req):
    req.redirect('/')

@web.wsgize
def login(req):
    pass

web.valid_user = lambda username, password: username == password
web.user_roles = lambda username: [username]
@web.auth('admin')
@web.wsgize
def private(req):
    return '<html><body>Private</body></html>'

urls = web.URLs()
urls.add('/', GET=index)
urls.add('/exception', GET=exception)
urls.add('/redirect', GET=redirect)
urls.add('/login', GET=web.login_form, POST=web.login)
urls.add('/logout', GET=web.logout)
urls.add('/private', GET=private)

if __name__ == '__main__':
    web.run(urls, globals(), debug=True, profile=True, session=web.session)
